﻿namespace App.Controls

open System
open System.Windows
open System.Windows.Controls
open System.Windows.Markup
open System.Windows.Input
open System.Collections.ObjectModel
open App.Commands
open App.Data

type SampleControl() as self=
        inherit UserControl()

        [<DefaultValue>]
        val mutable rootLayout : Grid        

        let books = new ObservableCollection<Book>()
        let loadCommand = new DelegateCommand(self.FillData)
            
        do
            self.rootLayout <- Application.LoadComponent(new System.Uri("/App;component/Control/SampleControlLayout.xaml", UriKind.Relative)) :?> Grid                             
            self.rootLayout.DataContext <- self            
            self.Content <- self.rootLayout

        member private self.FillData x =
            BookRepository.GetBooks() |> Seq.iter books.Add                            

        member self.Books with get() = books

        member self.LoadCommand with get() = loadCommand